import { fileURLToPath, URL } from "node:url"

import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"

import AutoImport from "unplugin-auto-import/vite"
// 处理svg
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
import vueSetupExtend from "vite-plugin-vue-setup-extend"

import Components from "unplugin-vue-components/vite"
import eslintPlugin from "vite-plugin-eslint"
import {
  AntDesignVueResolver,
  ElementPlusResolver,
  VantResolver,
  HeadlessUiResolver,
  ElementUiResolver
} from "unplugin-vue-components/resolvers"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    eslintPlugin({
      include: ["src/**/*.ts", "src/**/*.js", "src/**/*.vue", "src/*.ts", "src/*.vue", "src/*.js"]
    }),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.vue?$/, /\.md$/, /\.[tj]s?$/],
      imports: ["vue", "vue-router", "pinia"],
      eslintrc: {
        enabled: false,
        filepath: "./.eslintrc-auto-import.json",
        globalsPropValue: true
      },
      defaultExportByFilename: false,
      dirs: ["./src/components"],
      dts: "./auto-imports.d.ts",
      resolvers: []
    }),
    // svg
    createSvgIconsPlugin({
      iconDirs: [fileURLToPath(new URL("./src/assets/icons/svg/", import.meta.url))]
    }),
    vueSetupExtend(),
    Components({
      resolvers: [
        AntDesignVueResolver(),
        ElementPlusResolver(),
        VantResolver(),
        HeadlessUiResolver(),
        ElementUiResolver()
      ]
    })
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url))
    },
    extensions: [".js", ".ts", ".jsx", ".tsx", ".mjs", ".json", ".vue"]
  },
  css: {
    preprocessorOptions: {
      scss: {
        javascriptEnaled: true
      }
    }
  },
  optimizeDeps: {
    include: ["vue", "pinia", "axios", "vue-router", "element-plus"]
  }
})
